package odgs.app.server;

import org.jfree.data.general.DefaultPieDataset;

import odgs.Contents;
import odgs.ContentsFile;
import odgs.Directory;
import odgs.ExplorerNode;
import odgs.LoginedGridNode;
import odgs.listener.ServerManagerListener;
import odgs.manager.ServerManager;

public class GridNodeStateGraphController implements ServerManagerListener{
	private StateGraphUI ui;
	private ServerManager manager;
	private DefaultPieDataset data;

	public GridNodeStateGraphController(StateGraphUI ui) {
		this.ui = ui;
		data = ui.getData();
	}

	public void setServerManager(ServerManager manager) {
		this.manager = manager;
		manager.addServerManagerListener(this);
		updateData();
	}

	private void updateData() {
		int loginedCount = manager.getLoginedCount();
		int grids = manager.getGridNodeCount() - loginedCount;
		data.setValue("No Login Node", grids);
		data.setValue("Logined Node", loginedCount);
	}

	public void loginedNode(String id) {
		updateData();
	}
	
	public void freeStorage(ContentsFile file) {
		updateData();
	}
	public void joinedNode(String id) {
		updateData();
	}

	public void useStorage(ContentsFile file) {
		updateData();
	}

	public void logout(String id)
	{
		updateData();
	}

	public void addedContents(Contents contents){}
	public void addedDirectory(Directory directory){}
	public void error(int error){}
	public void removeContents(Contents contents) {}
	public void removeDirectory(Directory directory) {}
	public void serverOpened(int port) {}
	public void log(String log) {}
	public void updatedExplorerNode(String mode, ExplorerNode node, String name) {}
}
